# Maintainer: Bin Meng <bmeng.cn@gmail.com>

_realname=gptfdisk
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.0.8
pkgrel=1
pkgdesc="A text-mode partitioning tool that works on GUID Partition Table (GPT) disks (mingw-w64)"
arch=('x86_64')
mingw_arch=('mingw64' 'ucrt64')
url="https://www.rodsbooks.com/gdisk/"
license=('GPL2')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc")
depends=("${MINGW_PACKAGE_PREFIX}-popt")
options=('strip')
source=(https://downloads.sourceforge.net/project/${_realname}/${_realname}/$pkgver/${_realname}-$pkgver.tar.gz
        "0001-makefile-Drop-g-compiler-flag-for-mingw-builds.patch"
        "0002-makefile-Switch-to-building-shared-executables-for-m.patch"
        "0003-makefile-Fix-the-sgdisk-rule-for-mingw-builds.patch"
        "0004-makefile-Specify-std-c-14-for-mingw-builds.patch"
        "0005-makefile-Avoid-absolute-path-in-CXX-for-mingw-builds.patch"
        "0006-makefile-Omit-the-64-suffix-in-the-executable-names.patch")
sha256sums=('95d19856f004dabc4b8c342b2612e8d0a9eebdd52004297188369f152e9dc6df'
            '782a3623c68991a1b2803075969e5e1db92b2b717b02207c27aa874e1005ee9b'
            'df978d029bfc5215c42e832b4105fb5e55f90f411dca4f21250af057328b62d9'
            '96d67859cc8c52551263c7116031193acd03720d745f89a6e014e685b1cba5fd'
            '210b7bc9e3bec002e81daec379c6719e468a725beed1c74f998d77a9b014faff'
            '432d647bd28be95346631693bfc63775821766c8a64bd2b0e3976dde73f581d0'
            '6807d045f22d023a1d6778463fcced2727ffc8e10abccbb7a8df274e296bf091')

prepare() {
  cd "$srcdir/${_realname}-$pkgver"
  patch -p1 -i $srcdir/0001-makefile-Drop-g-compiler-flag-for-mingw-builds.patch
  patch -p1 -i $srcdir/0002-makefile-Switch-to-building-shared-executables-for-m.patch
  patch -p1 -i $srcdir/0003-makefile-Fix-the-sgdisk-rule-for-mingw-builds.patch
  patch -p1 -i $srcdir/0004-makefile-Specify-std-c-14-for-mingw-builds.patch
  patch -p1 -i $srcdir/0005-makefile-Avoid-absolute-path-in-CXX-for-mingw-builds.patch
  patch -p1 -i $srcdir/0006-makefile-Omit-the-64-suffix-in-the-executable-names.patch
}

build() {
  cd "$srcdir/${_realname}-$pkgver"
  make -f Makefile.mingw64
}

package() {
  cd "$srcdir/${_realname}-$pkgver"
  install -d "$pkgdir${MINGW_PREFIX}"/{bin,share/{doc/gdisk,man/man8}}
  install -t "$pkgdir${MINGW_PREFIX}/bin" {,s}gdisk.exe fixparts.exe
  install -m644 -t "$pkgdir${MINGW_PREFIX}/share/man/man8" {{,s}gdisk,fixparts}.8
  install -m644 -t "$pkgdir${MINGW_PREFIX}/share/doc/gdisk" README NEWS
}
